﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;

namespace MvcDatagrid.Models
{
    public class EmployeesRepository: IEmployeesRepository
    {
        private NorthwindEntities db = new NorthwindEntities();
        public IEnumerable<Employees> GetAllEmployees()
        {
            return db.Employees.ToList();
        }

        public Employees GetEmployeeById(int id)
        {
            return db.Employees.Single(e => e.EmployeeID == id);
            //return (Employees)(from employees in db.Employees 
            //        where employees.EmployeeID == id
            //        select employees);
        }

        public int AddEmployee(Employees employees)
        {
            db.Employees.AddObject(employees);
            return db.SaveChanges();
        }

        public int UpdateEmployees(Employees employees)
        {
            db.Employees.Attach(employees);
            db.ObjectStateManager.ChangeObjectState(employees, EntityState.Modified);
            return db.SaveChanges();
        }
        public int DeleteEmployees(Employees employees)
        {
            db.Employees.DeleteObject(employees);
            return db.SaveChanges();
        }
    }
}